//
//  TestRideTableCell.m
//  Cycling
//
//  Created by 迟国强 on 2023/3/28.
//

#import "TestRideTableCell.h"

@implementation TestRideTableCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.userIconV.layer.cornerRadius = 52/2;
    self.userIconV.layer.masksToBounds = YES;

    self.sectionInfoTitleLbl.text = CycLocalizedString(@"Test ride", @"试骑");
    
}
- (IBAction)refusedRide:(UIButton *)sender {
    if ([self.cancleBtn.titleLabel.text isEqualToString:CycLocalizedString(@"Waiting for acceptance", @"等待接受")] || [self.cancleBtn.titleLabel.text isEqualToString:CycLocalizedString(@"Waiting for confirmation to end", @"等待确认结束")]) {
        return;
    }
    
    if (self.refuseBlock) {
        BOOL type = [self.cancleBtn.titleLabel.text isEqualToString:CycLocalizedString(@"Decline", @"拒绝")] || [self.cancleBtn.titleLabel.text isEqualToString:CycLocalizedString(@"Cancel", @"取消")];
        self.refuseBlock(type);
    }
}
- (IBAction)acceptRide:(UIButton *)sender {
    if (self.acceptBlock) {
        self.acceptBlock(@"accept");
    }
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
    if (highlighted) {
        self.contentView.backgroundColor = COLOR_WHITE;
    }else{
        self.contentView.backgroundColor = COLOR_WHITE;
    }
    [super setHighlighted:highlighted animated:animated];
}

- (void)setModel:(Tryride *)model {
    _model = model;
    
    self.dateL.text = model.createtime;
    self.userNameL.text = model.nickname;
    self.sexL.text = model.gender;
    self.addressL.text = model.region;
    self.addressDLB.text = model.address;
    if([model.applystatus integerValue] == 1 && [model.tostatus integerValue] == 1) {
        self.mobileL.text = model.mobile;
    } else {
        self.mobileL.text = @"--";
    }
    [self.userIconV sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"icon_mine_head"]];
    /*
     cstatus=0显示接受和取消按钮
      cstatus=1和status=0显示等待接受
     cstatus=1和status=1和isend=0显示取消按钮
     status=1和cstatus=1和isend=1显示确认结束
     status=1和cstatus=3和isend=1显示等待确认结束
     */
    if([model.cstatus intValue] == 0){
        self.acceptBtn.hidden = NO;
        [self.acceptBtn setTitle:CycLocalizedString(@"Accept", @"接受") forState:(UIControlStateNormal)];
        [self.cancleBtn setTitle:CycLocalizedString(@"Decline", @"拒绝") forState:(UIControlStateNormal)];
        self.canWidth.constant = 154;
    }
    if([model.status intValue] == 0 && [model.cstatus intValue] == 1){
        self.acceptBtn.hidden = YES;
        [self.cancleBtn setTitle:CycLocalizedString(@"Waiting for acceptance", @"等待接受") forState:(UIControlStateNormal)];
        self.canWidth.constant = SCREEN_W - 40;
    }
    if([model.status intValue] == 1 && [model.cstatus intValue] == 1 && [model.isend intValue] == 0){
        self.acceptBtn.hidden = YES;
        [self.cancleBtn setTitle:CycLocalizedString(@"Cancel", @"取消") forState:(UIControlStateNormal)];
        self.canWidth.constant = SCREEN_W - 40;
    }
    if([model.status intValue] == 1 && [model.cstatus intValue] == 1 && [model.isend intValue] == 1){
        self.acceptBtn.hidden = YES;
        [self.cancleBtn setTitle:CycLocalizedString(@"Confirm End" , @"确认结束") forState:(UIControlStateNormal)];
        self.canWidth.constant = SCREEN_W - 40;
    }
    if([model.status intValue] == 1 && [model.cstatus intValue] == 3 && [model.isend intValue] == 1){
        self.acceptBtn.hidden = YES;
        [self.cancleBtn setTitle:CycLocalizedString(@"Waiting for confirmation to end", @"等待确认结束") forState:(UIControlStateNormal)];
        self.canWidth.constant = SCREEN_W - 40;
    }

}

@end
